package com.beiding.service.search.impl;

import com.beiding.dao.LocalRoomSearchDao;
import com.beiding.pojo.local.LocalRoom;
import com.beiding.pojo.room.Room;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RoomAspect { //这是一个对房间的保存删除等操作的切面集合

    private LocalRoomSearchDao searchDao;

    @Autowired
    public void setSearchDao(LocalRoomSearchDao searchDao) {
        this.searchDao = searchDao;
    }

    //在添加房源之后
    @AfterReturning(returning = "room",value = "execution(com.beiding.pojo.room.Room com.beiding.service.storage.RoomStorageService.put(..))")
    void afterPut(Room room) {

        searchDao.save(LocalRoom.getInstance(room));

    }

    //在删除房源之后
    @AfterReturning(value = "execution(void com.beiding.service.storage.RoomStorageService.remove(..))&&args(id)")
    void afterRemove(String id){
        searchDao.deleteById(id);
    }


    //更新以后
    @AfterReturning(returning = "room",value = "execution(com.beiding.pojo.room.Room com.beiding.service.storage.RoomStorageService.update(..))")
    void afterUpdate(Room room) {//更新
        searchDao.save(LocalRoom.getInstance(room));
    }

}
